package viewcomponents
{
	import model.*;
	
	import mx.containers.VBox;
	import mx.controls.Label;
	import mx.core.UIComponent;

	public class DetailsViewer extends VBox
	{
		public var selectedItem:Object;
		public var localData:LocalData;

		public function DetailsViewer()
		{
			super();
			var l:Label = new Label();
			l.text = "Please select an item on the left.";
			this.addChild(l);
		}

		public function setView( component:UIComponent ):void
		{
			removeAllChildren();
			addChild( component );
		}

    	public function selectionChange( ):void
    	{
    		var view:VBox;
			if ( selectedItem is ProjectVO )
			{
				view = new ProjectView();
				(view as ProjectView).viewer = this;
				(view as ProjectView).project = selectedItem as ProjectVO;
			}
			if ( selectedItem is CategoryVO )
			{
				view = new CategoryView();
				(view as CategoryView).viewer = this;
				(view as CategoryView).category = selectedItem as CategoryVO;
			}
			if ( selectedItem is TaskVO )
			{
				view = new TaskView();
				(view as TaskView).viewer = this;
				(view as TaskView).task = selectedItem as TaskVO;
				(view as TaskView).localData = localData;
			}
			setView( view );
    	}
    	
		public function onNewProject():void
		{
			var form:ProjectForm = new ProjectForm();
			form.viewer = this;
			setView( form );
		}
		public function onNewCategory():void
		{
			var form:CategoryForm = new CategoryForm();
			form.viewer = this;
			setView( form );
		}
		public function onNewTask():void
		{
			var form:TaskForm = new TaskForm();
			form.viewer = this;
			form.localData = localData;
			setView( form );
		}

		
	}
}